package com.controller;

import com.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * version 1.0.0
 *
 * @author KKW
 * @date 2017/7/7.
 */
@Controller
public class NewsController {
    @Autowired
    NewsService newsService;
    /**
     *
     * @param model 添加了视图page中的attribute信息，也就是requestPage中属性信息，由request带来
     * @return
     */
    @RequestMapping(value = "newsPage")
    public String news(Model model){
        long sttime=System.currentTimeMillis();
        model.addAttribute("newsa",newsService.getAllNews().get(0));
        model.addAttribute("readTime",System.currentTimeMillis()-sttime);
        model.addAttribute("flag","无cache");
        return "newsPage";
    }

    @RequestMapping(value = "newsCache")
    public String newsWithCache(Model model){
        long sttime=System.currentTimeMillis();
        model.addAttribute("newsa",newsService.getAllNewsCache().get(0));
        model.addAttribute("readTime",System.currentTimeMillis()-sttime);
        model.addAttribute("flag","有cache");
        return "newsPage";
    }
}
